package com.xu.mylol.acyivity;

import android.graphics.Color;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.xu.mylol.fragment.Fragment_Data;
import com.xu.mylol.fragment.Fragment_Image;
import com.xu.mylol.fragment.Fragment_Query;
import com.xu.mylol.fragment.Fragment_Video;
import com.xu.mylol.R;
import com.xu.mylol.adapter.TabAdapter;
import com.xu.mylol.fragment.Fragment_News;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    private ArrayList<Fragment> datas;
    private ViewPager viewPager;
    private TabAdapter tabAdapter;
    private TabLayout tabLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        viewPager = (ViewPager) findViewById(R.id.viewpaper);
        tabLayout = (TabLayout) findViewById(R.id.tab);
        tabLayout.setSelectedTabIndicatorColor(0xff0088ff);
        datas = new ArrayList<>();
        datas.add(new Fragment_News());
        datas.add(new Fragment_Data());
        datas.add(new Fragment_Query());
        datas.add(new Fragment_Video());
        datas.add(new Fragment_Image());
        tabAdapter = new TabAdapter(getSupportFragmentManager(),datas,this);
        viewPager.setAdapter(tabAdapter);
        tabLayout.setupWithViewPager(viewPager);

        tabLayout.setTabTextColors(Color.BLACK,Color.GREEN);

        for (int i = 0; i < tabLayout.getTabCount(); i++) {
            TabLayout.Tab tab = tabLayout.getTabAt(i);
            if (tab != null) {
                tab.setCustomView(tabAdapter.getTabview(i));
            }
        }
    }
}
